package com.agent.commons.Result;

import com.agent.commons.errorcode.ErrorCode;
import lombok.Data;

/**
 * WS信息传递格式
 * @param <T>
 */
@Data
public class NoticeResult<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 信息描述
     */
    private String message;

    /**
     * 传递数据
     */
    private T data;

    /**
     * 成功结果封装
     * @return
     * @param <T>
     */
    public static <T> NoticeResult<T> success(T data) {
        NoticeResult<T> result = new NoticeResult<>();
        result.code=200;
        result.message="success";
        result.setData(data);
        return result;
    }

    /**
     * 成功结果封装
     */
    public static <T> NoticeResult<T> success() {
        NoticeResult<T> result = new NoticeResult<>();
        result.code=200;
        result.message="success";
        return result;
    }

    /**
     * 成功结果封装
     */
    public static <T> NoticeResult<T> success(String message) {
        NoticeResult<T> result = new NoticeResult<>();
        result.code=200;
        result.message=message;
        return result;
    }

    /**
     * 错误结果封装
     * @param code
     * @return
     * @param <T>
     */
    public static <T> NoticeResult<T> error(ErrorCode  code) {
        NoticeResult<T> result = new NoticeResult<>();
        result.code=code.getCode();
        result.message= code.getMessage();
        return result;
    }

}
